import java.util.ArrayList;
import java.util.List;

/**
 * Created by xuguangyuansh on 2018/8/23.
 */
public class Peers {

    /** 当前指定的组织名称 */
    private String orgName; // Org1

    /** 当前指定的组织 ID */
    private String orgMSPID;    // Org1MSP

    /** 当前指定的组织所在根域名 */
    private String orgDomainName;   // org1.example.com

    /** peer 本地节点集合 */
    private List<Peer> peers = peers = new ArrayList<>();

    public Peers() {    }

    public Peers(String orgName, String orgMSPID, String orgDomainName) {
        this.orgName = orgName;
        this.orgMSPID = orgMSPID;
        this.orgDomainName = orgDomainName;
    }

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    public String getOrgMSPID() {
        return orgMSPID;
    }

    public void setOrgMSPID(String orgMSPID) {
        this.orgMSPID = orgMSPID;
    }

    public String getOrgDomainName() {
        return orgDomainName;
    }

    public void setOrgDomainName(String orgDomainName) {
        this.orgDomainName = orgDomainName;
    }

    /** 新增本地节点服务器 */
    public void addPeer(String peerName, String peerEventHubName, String peerLocation,
                        String peerEventHubLocation, String caLocation) {
        peers.add(new Peer(peerName, peerEventHubName, peerLocation, peerEventHubLocation, caLocation));
    }

    /** 获取本地节点服务器集合 */
    public List<Peer> get() {
        return peers;
    }


    /**
     * 节点器对象
     *
     * @auth xuguangyuansh
     *
     * @date 2018-08-23
     * @email xxx@126.com
     */
    public class Peer {

        /** 当前指定的组织节点域名 */
        private String peerName;    // e.g. peer0.org1.example.com

        /** 当前指定的组织节点事件域名 */
        private String peerEventHubName;    // e.g. peer0.org1.example.com

        /** 当前指定的组织节点访问地址 */
        private String peerLocation;    // e.g. grpc://110.131.116.21:7051

        /** 当前指定的组织节点事件监听访问地址 */
        private String peerEventHubLocation;    // e.g. grpc://110.131.116.21:7053

        /** 当前指定的组织节点 ca 访问地址 */
        private String caLocation;      // e.g. http://110.131.116.21:7054

        /** 当前 peer 是否增加 Event 事件处理 */
        private boolean addEventHub = false;

        public Peer(String peerName, String peerEventHubName, String peerLocation,
                    String peerEventHubLocation, String caLocation) {
            this.peerName = peerName;
            this.peerEventHubName = peerEventHubName;
            this.peerLocation = peerLocation;
            this.peerEventHubLocation = peerEventHubLocation;
            this.caLocation = caLocation;
        }

        public String getPeerName() {
            return peerName;
        }

        public void setPeerName(String peerName) {
            this.peerName = peerName;
        }

        public String getPeerEventHubName() {
            return peerEventHubName;
        }

        public void setPeerEventHubName(String peerEventHubName) {
            this.peerEventHubName = peerEventHubName;
        }

        public String getPeerLocation() {
            return peerLocation;
        }

        public void setPeerLocation(String peerLocation) {
            this.peerLocation = peerLocation;
        }

        public String getPeerEventHubLocation() {
            return peerEventHubLocation;
        }

        public void setPeerEventHubLocation(String peerEventHubLocation) {
            this.peerEventHubLocation = peerEventHubLocation;
        }

        public String getCaLocation() {
            return caLocation;
        }

        public void setCaLocation(String caLocation) {
            this.caLocation = caLocation;
        }

        public boolean isAddEventHub() {
            return addEventHub;
        }

        public void addEventHub(boolean addEventHub) {
            this.addEventHub = addEventHub;
        }
    }
}
